/*
* Copyright (C) 2008-2009 J-P Nurmi jpnurmi@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* $Id: messageview.h 587 2009-05-19 20:19:17Z jpnurmi $
*/

#ifndef MESSAGEVIEW_H
#define MESSAGEVIEW_H

#include "ui_messageview.h"

class QTreeView;
class Completer;
class NickHighlighter;
class CompletionModel;
namespace Irc { class Buffer; }

class MessageView : public QWidget
{
    Q_OBJECT

public:
    MessageView(Irc::Buffer* buffer, QWidget* parent = 0);
    ~MessageView();

    Irc::Buffer* buffer() const;
    void setBuffer(Irc::Buffer* buffer);

    CompletionModel* completionModel() const;
    void setCompletionModel(CompletionModel* model);

    QString senderHtml(const QString& sender) const;

    void receiveMessage(const QString& format, const QStringList& params, bool highlight = false);

public slots:
    void clear();

protected:
    bool eventFilter(QObject* receiver, QEvent* event);

signals:
    void send(const QString& text);
    void query(const QString& nick);
    void command(const QString& command);

private slots:
    void ctcpActionReceived(const QByteArray& prefix, const QByteArray& action);
    void ctcpReplyReceived(const QByteArray& prefix, const QByteArray& reply);
    void ctcpRequestReceived(const QByteArray& prefix, const QByteArray& request);
    void messageReceived(const QByteArray& prefix, const QByteArray& message);
    void noticeReceived(const QByteArray& prefix, const QByteArray& notice);
    void numericMessageReceived(const QByteArray& prefix, uint code, const QByteArray& message);

    void onSend();
    void moveToNextPage();
    void moveToPrevPage();
    void onAnchorClicked(const QUrl& link);
    void applySettings();
    void append(const QString& message, bool highlight = false);

private:
    struct MessageViewData : public Ui::MessageView
    {
        mutable QString prefixCache;
        Irc::Buffer* buffer;
        Completer* completer;
        NickHighlighter* highlighter;
        QTreeView* debugView;
    } d;
};

#endif // MESSAGEVIEW_H
